package com.xuzhijie.pms.utils;

import cn.hutool.json.JSONUtil;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class articleUtil {

    public Hitokoto generaArticle() throws Exception{
        URL url = new URL("https://v1.hitokoto.cn/");
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("GET");
        connection.setRequestProperty("User-Agent", "Java");
        int responseCode = connection.getResponseCode();
        System.out.println("Response Code: " + responseCode);
        BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
        StringBuilder response = new StringBuilder();
        String line;
        while ((line = reader.readLine()) != null) {
            response.append(line);
        }
        reader.close();
        connection.disconnect();
        String s = response.toString();
        Hitokoto hitokoto = JSONUtil.toBean(s, Hitokoto.class);

        return hitokoto;
    }

}
